﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class state_Play : MonoBehaviour
{
	Game game = new Game ();

	private int AudioIndex = 0;

	public int playerSpeedMax = 150;
	public int playerSpeedAdd = 30;
	public float playerPushSpeed = -8f;
	public float playerPushHoldTime = 0.3f;
	public float playerPushHoldScale = 0.1f;
	public float playerHSpeed = 5.0f;
	// Use this for initialization
	UnityEngine.UI.Text txt;

	void Start ()
	{

		game.Init (this);

		var btn = this.transform.Find ("btnWin").GetComponent<UnityEngine.UI.Button> ();
		btn.onClick.AddListener (onBtnWin);

		txt = this.transform.Find ("Text").GetComponent<UnityEngine.UI.Text> ();

		//sp=this.transform.Find
	}

	public void changeBGM (int level)
	{
		switch (level) {
		case 1:
			GameObject.Find ("AudioSource1").GetComponent<AudioSource> ().Play ();
			break;
		case 2:
			GameObject.Find ("AudioSource1").GetComponent<AudioSource> ().Play ();
			GameObject.Find ("AudioSource2").GetComponent<AudioSource> ().Play ();
			break;
		case 3:
			GameObject.Find ("AudioSource1").GetComponent<AudioSource> ().Play ();
			GameObject.Find ("AudioSource2").GetComponent<AudioSource> ().Play ();
			GameObject.Find ("AudioSource3").GetComponent<AudioSource> ().Play ();
			break;
		case 4:
			GameObject.Find ("AudioSource1").GetComponent<AudioSource> ().Play ();
			GameObject.Find ("AudioSource2").GetComponent<AudioSource> ().Play ();
			GameObject.Find ("AudioSource3").GetComponent<AudioSource> ().Play ();
			GameObject.Find ("AudioSource4").GetComponent<AudioSource> ().Play ();
			break;
		}
	}

    public void changeAudioFx(int type)
    {
        switch (type)
        {
            case 0:
                GameObject.Find("AudioFxAbsorb").GetComponent<AudioSource>().Play();
                break;
            case 1:
                GameObject.Find("AudioFxDie").GetComponent<AudioSource>().Play();
                break;
            case 2:
                GameObject.Find("AudioFxPunch").GetComponent<AudioSource>().Play();//
                break;
            case 3:
                GameObject.Find("AudioFxSpawn").GetComponent<AudioSource>().Play();//Coin
                break;
        }
    }

	void onBtnMusic ()
	{
		AudioBGMPlay (AudioIndex);
		AudioIndex++;
	}

	void onBtnWin ()
	{
		game.BeginWin ();
	}
		
	// Update is called once per frame
	void Update ()
	{
		game.Update ();
		txt.text = "X" + game.playerInfo.coin;
	}

	void AudioBGMPlay (int i)
	{
		switch (i) {
		case 0:
			GameObject.Find ("AudioSource1").GetComponent<AudioSource> ().Play ();
			break;
		case 1:
			GameObject.Find ("AudioSource2").GetComponent<AudioSource> ().Play ();
			break;
		case 2:
			GameObject.Find ("AudioSource3").GetComponent<AudioSource> ().Play ();
			break;
		case 3:
			GameObject.Find ("AudioSource4").GetComponent<AudioSource> ().Play ();
			break;
		}
	}

	void AudioFxPlay (int i)
	{

	}
}

